import * as actionTypes from './constant';

import {
  getTopTenRequest,
  getFavorRequest,
  getCategorySaleRequest,
  getAddressSaleRequest,
  getCategoryCountRequest,
} from '../../../../../services/main/dashboard';

export const changeTopTenAction = () => {
  return async (dispatch) => {
    await getTopTenRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_TOP_TEN,
        topTen: res.data,
      });
    });
  };
};

export const changeFavorAction = () => {
  return async (dispatch) => {
    await getFavorRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_FAVOR,
        favor: res.data,
      });
    });
  };
};

export const changeCategorySaleAction = () => {
  return async (dispatch) => {
    await getCategorySaleRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_CATEGORY_SALE,
        categorySale: res.data,
      });
    });
  };
};

export const changeAddressSaleAction = () => {
  return async (dispatch) => {
    await getAddressSaleRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_ADDRESS_SALE,
        addressSale: res.data,
      });
    });
  };
};

export const changeCategoryCountAction = () => {
  return async (dispatch) => {
    await getCategoryCountRequest().then((res) => {
      dispatch({
        type: actionTypes.CHANGE_CATEGORY_COUNT,
        categoryCount: res.data,
      });
    });
  };
};
